require "proto/jpush/message/ReqPushMessage"

PushManager = {}

function PushManager.Init()
    PushManager.PushTimeBox()
end

--[[
    --@pushType:推送类型 EnumConst.PushType
]]
function PushManager.Req_AddPush(pushType)
    if (Application.platform == RuntimePlatform.Android or Application.platform == RuntimePlatform.IPhonePlayer) and Config.isOpenSDK then
        if PushManager.GetRegistrationId() == "" then
            print("RegistrationId is nil,stop push")
            return
        end
        local req           = ReqPushMessage.New()
        req.registrationId  = PushManager.GetRegistrationId()
        req.JPFuncType      = pushType
        req.name            = getLanguage("PushTitleText" .. pushType)
        req.content         = getLanguage("PushText" .. pushType)
        local timeFunc      = PushManager["GetTime_Type" .. pushType]
        req.time            = timeFunc()
        req.channelId       = Config.SDK_Channel
        -- logError("添加推送111：" .. timeFunc())
        sendReqMessage(req)
        -- logError("添加推送：" .. tostring(req.time))
    end
end

function PushManager.GetRegistrationId()
    --if PushManager.regId == nil then
    --    PushManager.regId = JPush.JPushBinding.GetRegistrationId()
    --end
    return  PushManager.regId or ""
end

----------------------------time func
--计算挂机上限时间
local caculateHookMaxDate = function()
    local default = G.dataTable["t_global"]["95"].f_int_value
    local vip_level = logicMgr.VipManager.getVipLevel() 
    if vip_level > 1 then
        local buffs = logicMgr.VipManager.getVipEcoBuff()
        local value = 0
        for i, v in ipairs(buffs) do
            local buff = G.dataTable["t_ecobuff"][tostring(v)]
            if buff["f_BuffType"] == 4 then
                value = value + buff["f_BuffEffectValue"][1]
            end
        end
        return value
    else
        return default
    end
end

--暗巷开启时间
local getDarkStreetOpenTime = function()
    local time = HelperFunc.GetServerTime()
    local _end = logicMgr.DarkStreetMgr.GetEndTime()

    return _end - time
end

--下次公会战开启时间
local getUnionWarOpenTime = function()
    local t = os.date("*t", HelperFunc.GetServerTime())
end

--被突袭
function PushManager.PushStrike()
    
end

--时光魔晶可以领取
function PushManager.PushTimeBox()
    local boxInfo = TimeBoxHandler.GetTimeBoxInfo()
    local st,et = nil,nil
    for k,v in pairs(boxInfo) do
        st, et = TimeBoxHandler.GetBoxTime(v.slot + 1, k)
        if st and et then
            
        end
    end
end

--起源之战
function PushManager.PushOriginBattle()
    local time = logicMgr.CronMgr.GetNextDateTime(G.dataTable["t_global"]["214"]["f_string_value"],int64ToNumber(HelperFunc.GetServerTime()))

end

function PushManager.GetTime_Type1()
    local next = caculateHookMaxDate()
    if next then
        local sec = HelperFunc.GetServerTime(true)

        return sec + next
    end
end
----------------------------time func end

return PushManager